[alias]
  go = checkout
  status-clean = status --short
  grp = grep --break --heading --line-number
  diff-clean = diff --word-diff --ignore-all-space
  diff-staged = diff --word-diff --ignore-all-space --staged
  delete = branch --delete
  unstage = reset
	uncommit = reset --soft HEAD^
	discard = checkout --
	add-patch = add --patch
	discard-patch = checkout --patch
	unstage-patch = reset --patch
	stash-patch = stash --patch
	amend = commit --amend --reuse-message=HEAD

# James Brown school of git
	down = pull
	onup = push

# Create branch and take to it
	take = checkout -b

# Undo last N commits (HEAD~N); Go back to commit hash as HEAD
	undo-for-good = reset --hard

# Remove directory without deleting it
	untrack-dir = rm --cached -r

# Remove file without deleting it
	untrack-file = rm --cached

# Show untracked & ignored resources
	untracked = clean -dX --dry-run

# Delete local branches deleted on remote
	prune = fetch --prune

# Track remote branch
	track-branch = checkout --track

# Sneak changes into last commit
	sneak = commit --amend --no-edit

# Check local ref is up-to-date w/upstream before overwriting it. Only if we MUST
	please = push --force-with-lease

# Stash unstaged changes to tracked files only
	aside = stash push --quiet --keep-index

# Draw latest stash back
	draw = stash pop --quiet

# Stash untracked and tracked files
	amass = stash push --quiet --include-untracked

# Stash ignored, untracked, and tracked files
	hoard = stash push --quiet --all

## Prefixed bang (!) turns values into shell commands

# List aliases
	alias = "! git config --get-regexp alias | sed -e 's/alias.//' -e 's/ / = /' | sort"

# Init empty repo for rebase best practice
	it = "!git init && git commit -m \"Init $(basename $(pwd))\" --allow-empty"

# Show main repo's URL
	url = "! . ~/.githelpers && git_repo_url"

# Show help online; configured in [browser] section below
	help-web = "! git help $1 --web"

# Show all branches and when was the last time they were changed
	wip = for-each-ref --sort='authordate:iso8601' --format=' %(color:green)%(authordate:relative)%09%(color:white)%(refname:short)' refs/heads

# Show local branch commits not in public
	diff-local = "! . ~/.githelpers && git_diff_local"

# Show public branch commits not in local
	diff-public = "! . ~/.githelpers && git_diff_public"

# Show source branch commits not in local
	diff-source = "! . ~/.githelpers && git_diff_source"
	diff-source-details = diff upstream..main
	diff-source-details-legacy = diff upstream..master

# Catch up with upstream's changes
	catchup = "! .~/.githelpers && git_catchup_source"

# delete all local branches which have already been merged in public repo
	clean-pub = "! . ~/.githelpers && git_clean_public_repo"

# delete all merged branches from public repo
	prune-pub = "! . ~/.githelpers && git_prune_public_repo"

# Show full diff of changes not merged into current branch
	feature = log -p -m --first-parent

# Show announcement style log; summarized, commit count
	count = shortlog --summary --numbered

# Simple log (monochrome) `* commit message (SHA)`
	log-clean = log --pretty=format:'* %s (%h)'

# Pretty log (w/graph) `SHA, message, time ago, author`
	log-pretty = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'

# Abridged log (w/graph) `SHA, description`
	log-abridged = log --pretty=oneline --graph --abbrev-commit

# Own commits; last XX days `git log-since 30`
	log-since = "!sh -c \"git log --since '${1:-1} days ago' --oneline --author $(git config user.email)\" -"

# All commits; current branch, semi-detailed
	log-info = "!. ~/.githelpers && pretty_git_log"

# Recent commits; current branch only
	log-recent = log -30

# Recent commits; all reachable refs
	log-reachable = log --reflog --all --oneline --graph --decorate

# All commits; all reachable refs
	log-all = log --all

# Show commit details
	details = show --pretty='' --name-status

# Create a new browser command and configure help -w to use it. eg. git help log -w
[browser "gitscm"]
  cmd = "/bin/sh -c 'open https://git-scm.com/docs/$(basename $1 .html)' --"

[core]
	excludesfile = ~/.gitignore_global # TODO use default .config/git/ignore
	editor = emacs
# TODO remove for non-macOS
# Safer `git rebase` on macOS: http://www.git-tower.com/blog/make-git-rebase-safe-on-osx/
  trustctime = false

[init]
	defaultBranch = trunk

[color]
  ui = always
[color "diff"]
	meta = yellow
	frag = magenta # line span info
	old = red # deletions
	new = green # additions
[color "status"]
  added = yellow
  changed = green
  untracked = cyan

[diff]
  algorithm = histogram

[pager]
  diff = diff-highlight | less -R

[credential]
	helper = osxkeychain # TODO; which? keychain, gpg2

[grep]
  lineNumber = true

[help]
  autocorrect = 1 # auto-correct and execute command typos
  browser = gitscm

[pull]
  rebase = true

[push]
  default = current # match repos' branch name
	followTags = true # include reachable tags
	# gpgSign = if-asked # TODO add gpg for commits

[fetch]
  prune = true # Remove remote-tracking references no longer in remote

[hub]
  protocol = ssh

[http]
	saveCookies = false
	cookieFile = /dev/null

[format]
  signOff = true
	numbered = auto
	signature = "Cheers"
	outputDirectory = "./patch"
	coverLetter = true
	# signatureFile = ~/.gitsignature

[merge]
	tool = emacs
	conflictstyle = diff3
	summary = true
	ff = false
[mergetool]
  prompt = false
  keepBackup = false
[mergetool "emacs"]
	cmd = "emacs --merge --output \"$MERGED\" --base \"$BASE\" -- \"$LOCAL\" --snapshot \"$REMOTE\" --snapshot"
	trustExitCode = true

[include]
  path = ~/.gitpersonal # For username / github token / etc
